
#ifndef _READWRITE_3DS_H_
#define _READWRITE_3DS_H_

#include <BFile>
#include <BNode>
#include <BReadWrite>

#include "Chunk.h"
#include "Mate3DS.h"
#include "Mesh3DS.h"

using namespace BWE;

class ReadWrite_3ds : public BReadWrite
{
public:
	ReadWrite_3ds();
	~ReadWrite_3ds();

	virtual BObject* readObject(const BString& fileName);
	virtual bool writeObject(const BObject* object, const BString& fileName);

	virtual const BString& author() const;
	virtual const BString& version() const;
	virtual const BString& description() const;
	virtual const BString& log() const;

private:
	int readChunk(Chunk& chunk);
	bool passChunk(const Chunk& chunk);

	bool readChunkEditor(const Chunk& chunk);
	bool readChunkFramer(const Chunk& chunk);
	
	void readChunkMaterial(const Chunk& chunk);
	bool readChunkMesh(const Chunk& chunk);

	void readChunkMaterialTexture(const Chunk& chunk, Mate3DS* mate);
	bool readChunkMeshMesh(const Chunk& chunk, Mesh3DS* mesh);

	BColor readChunkColor(const Chunk& chunk);
	float readChunkPercent(const Chunk& chunk);

	Mate3DS* findMaterial(const BString& matName);

	void makeNormals(BMesh* mesh);

private:
	BFile					_file;
	BList<Mate3DSHolder>	_mates;
	BList<Mesh3DSHolder>	_geoms;

	BString			_author;
	BString			_version;
	BString			_description;
	BString			_log;
};

#endif